import os

import pandas as pd

from pprint import pprint


class DataOperation:
    def __init__(self, file,path,sheet=1):
        self.data = pd.read_csv(path)

        # 当输入的是csv文件时
        if file == 'csv':
            # 读取csv文件
            self.data = pd.read_csv(path)
        # 当输入的是excel文件时
        elif file == 'excel':
            # 读取excel文件
            self.data = pd.read_excel(path,sheet)
        elif file == 'mysql':
            # 当输入的是mysql文件时
            self.data = pd.read_sql(path,sheet)
        else:
            print('找不到文件')

    def get_data_to_dict(self):
        return [self.data.loc[i].to_dict() for i in self.data.index.values]


    def get_data_to_list(self):
        return self.data.values.tolist()


if __name__ == '__main__':
    path = os.path.join(os.path.dirname(os.path.abspath
                                        (__file__)), 'lj_data.csv')


    data = DataOperation('csv',path)
    pprint(data.get_data_to_list())